using System;
using System.Collections.Generic;

namespace DemonstrationWebsite.RecursiveFoldersDemo
{
    public partial class FoldersDemo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FoldersControl.Model["folders"] = GetInitialDataModel();
            }
        }

        private Folder GetInitialDataModel()
        {
            // Normally you'd retrieve this data from a database, but for this demo we'll use
            // some hard-coded data
            Folder root = new Folder("Steve's email");
            root.children.Add(new Folder("Inbox"));
            root.children.Add(new Folder("Sent"));
            
            Folder archive = new Folder("Archive");
            root.children.Add(archive);
            archive.children.Add(new Folder("Recent"));
            archive.children.Add(new Folder("Old"));

            return root;
        }
    }

    public class Folder
    {
        public string name;
        public List<Folder> children;

        // During a postback, you could inspect every aspect of the state of the folder tree (if you wanted to)
        public bool selected;
        public bool editing;
        public bool collapsed;

        public Folder() { } // Parameterless constructor necessary for deserialization
        public Folder(string name)
        {
            this.name = name;
            children = new List<Folder>();
        }
    }
}
